package com.lkd.controller;

import com.lkd.dto.PartnerDto;
import com.lkd.dto.RegionDto;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.vo.NodeVo;
import com.lkd.vo.RegionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class RegionController extends Result {

    @Autowired
    private com.lkd.service.RegionService regionService;

    // 1.1  区域搜索
    @GetMapping("api/vm-service/region/search")
    public Result findByPage(PartnerDto dto){
        PageBean<RegionVo> pageBean = regionService.findByPage(dto);
        return success(pageBean);
    }

    //1.2 新增区域
    @PostMapping("/api/vm-service/region")
    public Result add(@RequestBody RegionDto dto){
        Boolean result =regionService.add(dto);
        return success(result);
    }

    //1.3 修改区域
    @PutMapping("/api/vm-service/region")
    public Result update(@RequestBody RegionDto dto){
        Boolean result = regionService.update(dto);
        return success(result);
    }
    //1.4 根据区域id和点位名称查询点位信息
    @GetMapping("/api/vm-service/node/search")
    public Result findNodeByRegionId(RegionDto regionDto){
        PageBean<NodeVo> pageBean = regionService.findNodeByRegionId(regionDto);
        return Result.success(pageBean);
    }

    //1.5 通过id删除区域
    @DeleteMapping("/api/vm-service/region/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        Boolean result = regionService.deleteById(id);
        return success(result);
    }

}
